package com.yongbao.model.util;

import com.yongbao.model.dtomapper.DishSpecificationDtoMapper;
import com.yongbao.model.domain.DishSpecificationDO;
import com.yongbao.model.request.DishSpecificationRequest;
import com.yongbao.model.vo.DishSpecificationVO;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhanghong
 */
public class DishSpecificationConvert {

    public static List<DishSpecificationVO> buildDishSpecificationVoList(List<DishSpecificationDO> dishSpecificationDOList) {
        if (CollectionUtils.isEmpty(dishSpecificationDOList)) {
            return Lists.newArrayList();
        }
        List<DishSpecificationVO> dishSpecificationVOList = new ArrayList<>();
        for (DishSpecificationDO dishSpecificationDO : dishSpecificationDOList) {
            dishSpecificationVOList.add(DishSpecificationDtoMapper.INSTANCE.do2VO(dishSpecificationDO));
        }

        return dishSpecificationVOList;
    }

    public static List<DishSpecificationDO> buildDishSpecificationDOList(List<DishSpecificationRequest> dishSpecificationRequestList) {
        return buildDishSpecificationDOList(null, dishSpecificationRequestList);
    }

    public static List<DishSpecificationDO> buildDishSpecificationDOList(Long dishId, List<DishSpecificationRequest> dishSpecificationRequestList) {
        if (CollectionUtils.isEmpty(dishSpecificationRequestList)) {
            return Lists.newArrayList();
        }
        List<DishSpecificationDO> dishSpecificationVOList = new ArrayList<>();
        for (DishSpecificationRequest dishSpecificationRequest : dishSpecificationRequestList) {
            DishSpecificationDO dishSpecificationDO = DishSpecificationDtoMapper.INSTANCE.request2DO(dishSpecificationRequest);
            if (dishId != null) {
                dishSpecificationDO.setDishId(dishId);
            }
            dishSpecificationVOList.add(dishSpecificationDO);
        }

        return dishSpecificationVOList;
    }
}
